#include <iostream>
#include <vector>
#include "demo08.h"
#include "demo04.cpp"
#include "fiber.h"

Logger::ptr lg(new Logger("XYZ"));
//Logger::ptr lg = createLogger();

void func1(){
    while(true){
        SYLAR_LOG_INFO(lg)<< "***************";
    }
}
void func2(){
    while(true){
        SYLAR_LOG_INFO(lg)<<"================";
    }
}

int main(int argc, char** argv){

    LogFormatter::ptr formatter(new LogFormatter("%d{%Y-%m-%d %H:%M:%S}%T%t%T%F%T[%p]%T[%c]%T%f:%l%T%m%n"));
    FileLogAppender::ptr fileAP(new FileLogAppender("mutex.txt"));
    fileAP->setFormatter(formatter);
    lg->addAppender(fileAP);

    std::vector<Thread::ptr> thrs;
    for(int i = 0;i < 2;i ++){
        std::string name = "name_" + std::to_string(i);
        Thread::ptr thr(new Thread(&func1, name));
        Thread::ptr thr2(new Thread(&func2, name));
        thrs.push_back(thr);
        thrs.push_back(thr2);
    }
    for(int i = 0;i < thrs.size();i++){
        thrs[i]->join();
    }


    return 0;
}
